﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.TranslateApprove.Model;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.SoldierArchives.BLL;

public partial class Police_TranslateApprove_ApplyHistory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind(0);

    }

    private void Bind(int index)
    {
        //State说明：1:未审批，2:通过，3:驳回，4:跳过
        /////////////////////////////////////////////////////////////////////////////////////////////////////     
        MemberInfo info = Yipusoft.TranslateApprove.BLL.Members.GetMember(Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID);

        if (info == null)
            return;

        Yipusoft.TranslateApprove.Model.ProcessInfo pinfo = Yipusoft.TranslateApprove.BLL.Process.GetModelByRID(info.DID);
        if (pinfo == null)
            return;

        this.GvwList.DataSource = Yipusoft.TranslateApprove.BLL.Apply.GetHistoryListByPID(pinfo.PID, index, 10);
        this.ListPageContral1.ItemCount = Yipusoft.TranslateApprove.BLL.Apply.GetHistoryListCount(pinfo.PID);
        this.GvwList.DataBind();
    }
    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        Bind(PageIndex);
    }
    protected void GvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ApplyInfo info = e.Row.DataItem as ApplyInfo;

            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            
            TranslateLogInfo logInfo = TranslateLogs.GetDetailByDID(info.AID);
            Label lblSodierName = e.Row.FindControl("lblSodierName") as Label;
            TranslateInfo Tinfo = Translate.GetDetail(logInfo.FID);
            lblSodierName.Text = Tinfo.SoldierName;
        }
    }

    public string GetUserName(object obj)
    {
        if (obj == null)
            return "";
        return Yipusoft.Account.BLL.User.GetUser(obj.ToString()).UserName;


    }
    public string SubString(object obj, int len)
    {
        if (obj == null)
            return "";
        return obj.ToString().Length > len ? obj.ToString().Substring(0, len) + "..." : obj.ToString();
    }

    public string GetTitle(object obj, int len)
    {
        if (obj == null)
            return "";
        Yipusoft.TranslateApprove.Model.ApplyInfo info = Yipusoft.TranslateApprove.BLL.Apply.GetApply(new Guid(obj.ToString()));
        if (info == null)
            return "";
        return info.Title.Length > len ? info.Title.Substring(0, len) + "..." : info.Title;
    }
}
